#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n, m, k;
	cin >> n >> m >> k;
	int w;
	cin >> w;
	vector<int> a(w);
	for (int i = 0; i < w; i++) cin >> a[i];
	vector<vector<int>> grid(n + 1, vector<int>(m + 1));

	int ma = min(k, m - k + 1);
	int l = 1, r = m;
	while (l <= r)
	{
		if (l <= ma) grid[0][l] = l;
		else grid[0][l] = ma;
		if (r > m - ma) grid[0][r] = m - r + 1;
		else grid[0][r] = ma;
		l++, r--;
	}
	ma = min(k, n - k + 1);
	l = 1, r = n;
	while (l <= r)
	{
		if (l <= ma) grid[l][0] = l;
		else grid[l][0] = ma;
		if (r > n - ma) grid[r][0] = n - r + 1;
		else grid[r][0] = ma;
		l++, r--;
	}

	//	else
	//	{
	//		int ma = m-k+1;
	//		int l = 1, r = m;
	//		while(l <= r)
	//		{
	//			if(l <= ma) grid[0][l] = l;
	//			else grid[0][l] = ma;
	//			if(r > m-ma) grid[0][r] = m-r+1;
	//			else grid[0][r] = ma;
	//			l++,r--;
	//		}
	//		l = 1, r = n;
	//		while(l <= r)
	//		{
	//			if(l <= k) grid[l][0] = l;
	//			else grid[l][0] = k;
	//			if(r > n-k) grid[r][0] = n-r+1;
	//			else grid[r][0] = k;
	//			l++,r--;
	//		}
	//	}
	priority_queue<int> q;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) q.push(grid[0][j] * grid[i][0]), grid[i][j] = grid[0][j] * grid[i][0];

	//	for(int i = 0;i <= n;i++) 
	//	{
	//		for(int j = 0;j <= m;j++) 
	//			cout << grid[i][j] << ' ';
	//		cout << endl;
	//	}

	sort(a.begin(), a.end(), greater<int>());
	int ans = 0;
	for (int i = 0; i < w; i++)
	{
		ans += q.top() * a[i];
		q.pop();
	}
	cout << ans << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}